package com.acce.gxsc.page.outCar.batchDetail;

import com.acce.gxsc.model.WorkModel;
import com.acce.gxsc.model.loaclBean.ResultBean;
import com.acce.gxsc.model.netBean.NetBatchDetailBean;
import com.acce.sdk.base.mvp.BasePresenter;
import com.acce.sdk.utils.ToastUtils;

import rx.Subscriber;

/**
 * Created by huxley on 2017/5/26.
 */
public class BatchDetailPresenter extends BasePresenter<BatchDetailView> {

    public void loadBatchDetail(String inBatchId) {
        WorkModel.getInstance().loadBatchDetail(inBatchId).subscribe(new Subscriber<ResultBean<NetBatchDetailBean>>() {
            @Override
            public void onStart() {
                if (mViewRef != null) {
                    getView().showProgressDialog("加载中", false);
                }
            }

            @Override
            public void onNext(ResultBean<NetBatchDetailBean> datas) {
                if (mViewRef != null) {
                    if (!"200".equals(datas.returnCode)) {
                        ToastUtils.show(datas.returnMsg);
                        return;
                    }
                    getView().loadBatchDetailSuccess(datas.result);
                }
            }

            @Override
            public void onCompleted() {
                if (mViewRef != null) {
                    getView().hideProgressDialog();
                }
            }

            @Override
            public void onError(Throwable e) {
                if (mViewRef != null) {
                    e.printStackTrace();
                    getView().hideProgressDialog();
                }
            }
        });
    }
}
